*Function ProximoDia( dDia )
Parameters dDia, dMed

         Private dProx, regant, selant,dprox, ltalk
         
         if set('Talk') = 'ON'
            set talk off
            ltalk = .t.
           else
            ltalk = .f.
         endif
         
         m.dprox = dDia

         m.regant = recno()
         m.selant = select()
         
         Select Horarios
                Set order to tag Medico
                
         Seek dMed

         select feriados
                set order to data
         
         do while .t.
            m.dprox = m.dprox - 1
            m.cprox = str( dow( m.dProx ),1 )
         
            if Seek( m.dProx )
               loop
            endif
            
            if not horarios.Trabal_&cprox
               loop
            endif
            
            exit
         enddo

         select ( m.selant )
         if between(m.regant, 1, reccount() )
            goto ( m.regant )
         endif

         if ltalk 
            set talk on
         endif
         
return   (dProx)
